/*
 * @Author: szx
 * @Date: 2022-03-15 16:44:23
 * @LastEditTime: 2022-03-15 16:53:41
 * @Description:
 * @FilePath: \learn\MDN_JS学习\八股文\柯里化\柯里化.js
 */
function curry(fn, args = []) {
    return function () {
        let newArgs = args.concat(Array.from(arguments));
        // 每次调用时判断此时的参数是否足够，从而选择要调用 fn 还是继续进行柯里化
        if (fn.length > newArgs.length) {
            // fn.length获取了参数的数量
            return curry(fn, newArgs);
        } else {
            return fn.apply(this, newArgs);
        }
    };
}
const add = curry(function (a, b, c) {
    return a + b + c;
});
const a = 1,
    b = 2,
    c = 3;
add(a)(b);
// console.log(add(a));
// console.log(add(a)(b)(c));
// console.log(add(a, b)(c));
// console.log(add(a)(b, c));
// console.log(add(a, b, c));
